<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
      function arrayIntersect(a,b){
        const xlh = (item) =>{
          if (typeof item === 'object' && item !== null){
            return JSON.stringify(item)
          }
          return item
        }
        const xlhSetB = new Set(b.map(xlh))
        const xlhSetA = new Set(a.map(xlh))
        return [...xlhSetA].filter(item => {
          return xlhSetB.has(item)
        })
      }

      // 使用示例
      const array1 = [1, 2, 2, 1];
      const array2 = [2, 2];
      const result = arrayIntersect(array1, array2);
      console.log(result); // 输出 [2, 2]
</script>
</html>